package com.chey.service.impl;

import com.chey.dao.DfdlDao;
import com.chey.pojo.META;
import com.chey.pojo.blls.BELT;
import com.chey.pojo.dfdl.*;
import com.chey.service.DfdlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.UUID;

/**
 * @author JanYao
 * @version 0.1
 */
@Service
public class DfdlServiceImpl implements DfdlService {

    @Autowired
    private DfdlDao dfdlDao;

    @Override
    public void insert(MSG23 msg) {

        String dfdl_uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();

        dfdlDao.addMeta(dfdl_uuid, msg.getMeta());

        dfdlDao.addMSG(dfdl_uuid, msg);

        List<DFLT> data = msg.getData();
        for (DFLT dflt : data) {

            List<ARPT> arpts = dflt.getARPT();
            String arpt_uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();

            for (ARPT arpt : arpts) {
                //新增了aprt_uuid 用来数据库对应关系

                if (!ObjectUtils.isEmpty(arpt.getFPTT()) && "".equals(arpt.getFPLT())){
                    dfdlDao.addArptS(arpt_uuid,arpt);
                    System.out.println("1111111111111111111111"+arpt);
                }
                if ( !ObjectUtils.isEmpty(arpt.getFPTT()) && !ObjectUtils.isEmpty(arpt.getFPLT())){
                    System.out.println("22222222222222222222222"+arpt);
                    dfdlDao.addArptT(arpt_uuid,arpt);
                }
                if ("".equals(arpt.getFPTT()) && !ObjectUtils.isEmpty(arpt.getFPLT())){
                    dfdlDao.addArptE(arpt_uuid,arpt);
                    System.out.println("333333333333333333333333333"+arpt);
                }


            }
            List<BELT> belts = dflt.getBELT();
            for (BELT belt : belts) {

                dfdlDao.addBelt(dfdl_uuid, belt);
            }


            List<SFLT> sflt = dflt.getSflt();
            for (SFLT sflt1 : sflt) {

                dfdlDao.addSflt(dfdl_uuid, sflt1);
            }
            dfdlDao.addDflt(dfdl_uuid,arpt_uuid, dflt, dflt.getCkls(), dflt.getTMCD());
        }
    }
}
